<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@include file="/common/taglibs.jsp" %>
<%@include file="/common/javascript.jsp" %>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title> 用户管理</title>

    <script type="text/javascript">
		$(function(){
			$("#dg").datagrid({url:'manageGrid',rownumbers:true,singleSelect:false,selectOnCheck:true,
					fitColumns:true,pagination:true,loadMsg:'数据加载中...',
					columns:[[  
						{field:'ck',checkbox:true},  
						{field:'id',title:"序号",width:80,align:'center',hidden:true}, 
						{field:'num',title:"编号",width:80,align:'center'}, 
						{field:'name',title:"用户名称",width:100,align:'center'},
						{field:'permission',title:"用户权限",width:100,align:'center'},
						{field:'remark',title:"备注",width:80,align:'center'}
					]]  
			});
			
			$("#dg").datagrid('getPager').pagination({//分页栏下方文字显示
				showPageList:false,
				beforePageText:'第',
				afterPageText: '页    共 {pages} 页',            
			    displayMsg:'当前显示从第{from}条到{to}条 共{total}条记录'
			});
			
			$("#btnAdd").bind('click',function(){
				pageLoading(window.frames["openFrame"].document);
				$("#openFrame")[0].src="manageAction_toForm?viewType=add";
				$("#content").dialog({ title:'增加', width:600, height:250, closed:true, 
					minimizable:true, maximizable:true, modal:true,resizable:true,
					buttons:[{
					  text:'保存',
							handler:function(){
								openFrame.window.saveInfo();
							}
						},{
							text:'关闭',
							handler:function(){
								$("#content").dialog('close');
							}
						}]
				});
				$("#content").dialog('open');
			});
			
			$("#btnEdit").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows && rows.length>1){
					$.messager.alert('提示','请选择单一数据项修改',"info");
				}else{
					var row =$("#dg").datagrid('getSelected');
					if(row){
						pageLoading(window.frames["openFrame"].document);
						$("#openFrame")[0].src="manageAction_toForm?viewType=modify&model.id="+row.id;
						$("#content").dialog({ title:'修改', width:600, height:250, closed:true, 
							minimizable:true, maximizable:true,modal:true,resizable:true,
							buttons:[{
							  text:'保存',
									handler:function(){
										openFrame.window.saveInfo();
									}
								},{
									text:'关闭',
									handler:function(){
										$("#content").dialog('close');
									}
								}]
						});
						$("#content").dialog('open');
					}else{
						$.messager.alert('提示','请先选择要修改的数据项',"info");
					}	
				}
			});
			
			$("#btnDetail").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows && rows.length>1){
					$.messager.alert('提示','请选择单一用户',"info");
				}else{
					var row =$("#dg").datagrid('getSelected');
					if(row){
						pageLoading(window.frames["openFrame"].document);
						$("#openFrame")[0].src="manageAction_toForm?viewType=detail&model.id="+row.id;
						$("#content").dialog({ title:'查看', width:600, height:250, closed:true, 
							minimizable:true, maximizable:true,modal:true,resizable:true,
							buttons:[{
									text:'关闭',
									handler:function(){
										$("#content").dialog('close');
									}
								}]
						});
						$("#content").dialog('open');
					}else{
						$.messager.alert('提示','请先选择要修改的数据项',"info");
					}	
				}
			});
			
			$("#btnDelete").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows!=null && rows.length>0){
					$.messager.confirm('提示','确定要删除吗？',function(r){
						if (r){  
							var ids="";
							for(var i=0;i<rows.length;i++){
								ids+=rows[i].id+",";
							}
							$.post("manageAction_delete",{ids:ids},function(data){
								var data = eval('(' + data + ')');
								if (!data.success){ //删除失败  
									$.messager.alert('提示',"错误"+data.message,"info");
        						}else{//删除成功
        							$.messager.alert('提示',data.message,"info",function(){
        								$('#dg').datagrid('reload'); //刷新网格
        							});
        						} 
							});
						}
					});
				}else{
					$.messager.alert('提示','请先选择要删除的数据项',"info");
				}
			});
		});
		
		function closeContent(){
			$("#content").dialog('close');
			$('#dg').datagrid('reload');
		}
	</script>
</head>

<body style="margin:0px; overflow-style:clear; padding:0px;">
	<div id="toolbar" style="background:#C9DFFF" >
		<c:if test="${permissionId==1}">
    		<a id="btnAdd"  class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:'true'" style="text-align:center">增加</a>
        	<a id="btnEdit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:'true'" style="text-align:center">修改</a>
        	<a id="btnDelete" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:'true'" style="text-align:center">删除</a>
        </c:if>
        <a id="btnDetail" class="easyui-linkbutton" data-options="iconCls:'icon-detail',plain:'true'" style="text-align:center">详情</a>
    </div>
    <table id="dg"> </table>
    <div id="content" style="top: 100px;">
    	<iframe id="openFrame" name="openFrame" frameborder="0" scrolling="no"  src="" style="width:100%;height:95%;"></iframe> 
    </div> 
</body>
</html>

